// pages/myactivities/myactivities.js
Page({
    /**
     * 页面的初始数据
     */
    data: {
        registeredActivities: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.loadRegisteredActivities();
    },

    // 加载已报名活动
    loadRegisteredActivities() {
        const registeredActivities = wx.getStorageSync('REGISTERED_ACTIVITIES') || [];
        this.setData({
            registeredActivities
        });
    },

    // 取消报名
    cancelRegistration(e) {
        const id = e.currentTarget.dataset.id;
        let registeredActivities = this.data.registeredActivities;
        registeredActivities = registeredActivities.filter(item => item.id !== id);

        this.setData({
            registeredActivities
        });

        // 更新本地存储
        wx.setStorageSync('REGISTERED_ACTIVITIES', registeredActivities);

        // 提示用户
        wx.showToast({
            title: '已取消报名',
            icon: 'success'
        });
    },
});